package com.yuebook.reader.json.user;

import com.yuebook.base.common.dto.ResponseDTO;
import com.yuebook.reader.common.param.user.UserParamBean;
import com.yuebook.reader.common.vo.user.UserInfo;
import com.yuebook.reader.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author honglei
 * @date 2018/10/31 下午8:25
 */
@Api(description = "用户管理")
@Controller
@RequestMapping(value = "user", name = "用户管理")
public class UserAction {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "detail/{id}", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "detail/{id}", notes = "获取用户")
    public ResponseDTO getUserById(@ApiParam(required = true, value = "用户id") @PathVariable("id") Integer id) {
        UserInfo user = userService.getUserById(id);
        return ResponseDTO.success(user);
    }

    @RequestMapping(value = "add", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "add", notes = "获取用户")
    public ResponseDTO addUser(UserParamBean userParamBean) {
        Integer id = userService.addUser(userParamBean);
        return ResponseDTO.success(id);
    }
}
